﻿using System.Collections.Generic;

namespace MySqlQueryToolkit
{
    public class QueryHandler
    {
        private readonly IExplainQueryReporter _explainQueryReporter;
        private readonly IProfileQueryReporter _profileQueryReporter;
        private readonly ITimeQueryReporter _timeQueryReporter;

        public QueryHandler(IExplainQueryReporter explainQueryReporter, IProfileQueryReporter profileQueryReporter, ITimeQueryReporter timeQueryReporter)
        {
            _explainQueryReporter = explainQueryReporter;
            _profileQueryReporter = profileQueryReporter;
            _timeQueryReporter = timeQueryReporter;
        }

        public ViewData GetViewData(string query, bool shouldExplain, bool shouldProfile, bool shouldTime)
        {
            var viewData = new ViewData
            {
                ExplainResults = shouldExplain ? _explainQueryReporter.Report(query) : new List<ExplainQueryResult>(),
                ProfileResults = shouldProfile ? _profileQueryReporter.Report(query) : new ProfileQueryResult(),
                TimeResults = shouldTime ? _timeQueryReporter.Report(query) : new TimeQueryResult()
            };

            return viewData;
        }
    }
}
